home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5286 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: peer-news.britain.eu.net!demon!thesett.demon.co.uk
  2. From: Andy@thesett.demon.co.uk (Andy Goodwin)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: New printf - like function, is it possible?
  5. Date: Fri, 02 Feb 1996 17:08:31 GMT
  6. Message-ID: <31124386.1286150@news.demon.co.uk>
  7. References: <4eqb3a$2r5@pan.otol.fi>
  8. NNTP-Posting-Host: thesett.demon.co.uk
  9. X-NNTP-Posting-Host: thesett.demon.co.uk
  10. X-Newsreader: Forte Agent .99c/16.141
  11.  
  12. On 1 Feb 1996 12:18:50 GMT, tkes@rhea.otol.fi (Timo Sakari) wrote:
  13.  
  14. >
  15. >Hi!
  16. >
  17. >Do you C-gurus have any solutions to this problem?
  18. >
  19. >I am programming under MS Windows 3.1 (this is NOT an OS spesific 
  20. >question!)and I would like to create
  21. >some kind of modified print function, which syntax should be something
  22. >like normal printf; because in Windows printf can't be used, everything
  23. >printed to screen has to come through message boxes etc, and before 
  24. >displaying anything, the string to displayed has to be formed. I have 
  25. >created my own printing function, which wants parameters string and winID
  26. >to know where to put that string, something like this: 
  27. >
  28. >sprintf(printStr, "some sfuff, variables %d, %f, etc", var1, var2);
  29. >PrintToWin(DEBUG_WIN_1, printStr);
  30. >
  31. >However, I want to write a "better" printing function, where string to be
  32. >formed doesn't need to be formatted first, it can be displayed and formed
  33. >at the same time in the same syntax like printf, something like these:
  34. >
  35. >PrintToWin(DEBUG_WIN_1, "some stuff etc, %d, %f, %s, var1, var2, str1);
  36. >PrintToWin(OTHER_WIN, "anything that printf accepts");
  37. >
  38. >So I want to print almost anything with this function without having
  39. >to write many functions to different argument types/number of arguments.
  40. >This should be possible in C++ (is it?), but is it possible in C ?
  41. >Can this be achieved by using void pointers and macros etc., or should
  42. >I give up and don't waste my time on this?
  43. >
  44. >Any help would be greatly appreciated. Thanks.
  45. >
  46. >
  47. >
  48. >--
  49. >   Timo Sakari          phone: (981) 5306 070 
  50. >   Haapanatie 2 D 408   email: tkes@rhea.otol.fi
  51. >   90150 OULU           WWW: http://www.otol.fi/~tkes/
  52. >   FINLAND
  53.  
  54. Look at the folling functions in your C documentation
  55. type va_arg( va_list arg_ptr, type );
  56.  
  57. void va_end( va_list arg_ptr );
  58.  
  59. void va_start( va_list arg_ptr );    (UNIX version)
  60.     void va_start( va_list arg_ptr, prev_param );    (ANSI)
  61.  
  62. Microsoft C gives an example of how to average 'n' integers
  63.  
  64. Your function would have to be prototyped as :-
  65.  
  66. void PrintToWin( int, const char *, ... ) ;
  67.  
  68. You could then use the vsprintf function after generating a va_list
  69. variable and temporary buffer
  70.  
  71. eg
  72.  
  73. vsprintf( buffer, const char *format, va_list argptr );
  74.     
  75.